package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.player.RechargeModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;

import java.util.List;

/**
 * 触发现金礼包
 */
public class TriggerRMBRecharge extends BaseRecharge {

    public TriggerRMBRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        ActivityModule activityModule = player.getModule(ActivityModule.class);
        BaseActivityData activityData = activityModule.getBaseActivityData(mallInfo.getActivityId());
        if(null == activityData) {
            return true;
        }
        List<UserActivityConditionData> dataList = activityData.getUserActivityConditionDataList();
        UserActivityConditionData userActivityConditionData = null;
        for(UserActivityConditionData tempConditionData : dataList){
            if(tempConditionData.getValue().intValue() == mallInfo.getMallId()){
                userActivityConditionData = tempConditionData;
                break;
            }
        }
        if(null == userActivityConditionData){
            return true;
        }
        if (userActivityConditionData.isGetReward()) {
            return true;
        }else {
            if(0 != activityModule.queryActivityMallCanBuy(mallInfo.getActivityId(), userActivityConditionData.getConditionId())){
                return true;
            }
        }
        return false;
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        //现金礼包
        player.getModule(RechargeModule.class).notifyRMBMallActivity(mallInfo.getMallId());
        return mallInfo.getReward();
    }

}
